package com.eclub.emotion.rootstone.server.context;

import com.eclub.emotion.rootstone.protocol.Protocol;
import com.eclub.emotion.rootstone.protocol.sdp.RequestProtocol;
import com.eclub.emotion.rootstone.server.ServerHandler;
import com.eclub.emotion.rootstone.server.http.HttpContext;
import com.eclub.emotion.rootstone.server.http.HttpRequest;

public class RsContext {

	private boolean monitor;
	private StopWatch stopWatch = new StopWatch();
	private Request request = new Request();
	private Response response;
	private ServerType serverType;
	private Throwable error;
	private RsChannel channel;
	private ServerHandler serverHandler;
	private boolean isDoInvoke = true;
	private Protocol protocol ;
	private ExecFilterType execFilter = ExecFilterType.All;
	private HttpRequest httpResuest ;

	public RsContext() {
	}

	public RsContext(RsChannel channel) {
		this.setChannel(channel);
	}

	public RsContext(byte[] requestBuffer, RsChannel channel, ServerType serverType, ServerHandler handler) throws Exception {
		this.request.setRequestBuffer(requestBuffer);
		this.setChannel(channel);
		this.setServerType(serverType);
		this.setServerHandler(handler);
	}

	public static RsContext getFromThreadLocal() {
		return Global.getSingleton().getThreadLocal().get();
	}

	public boolean isMonitor() {
		return monitor;
	}

	public void setMonitor(boolean monitor) {
		this.monitor = monitor;
	}

	public Request getGaeaRequest() {
		return request;
	}

	public void setGaeaRequest(Request gaeaRequest) {
		this.request = gaeaRequest;

		RequestProtocol r = (RequestProtocol) gaeaRequest.getProtocol().getSdpEntity();
		this.stopWatch.setLookup(r.getLookup());
		this.stopWatch.setMethodName(r.getMethodName());
	}

	public Response getGaeaResponse() {
		return response;
	}

	public void setGaeaResponse(Response gaeaResponse) {
		this.response = gaeaResponse;
	}

	public StopWatch getStopWatch() {
		return stopWatch;
	}

	public void setDoInvoke(boolean isDoInvoke) {
		this.isDoInvoke = isDoInvoke;
	}

	public boolean isDoInvoke() {
		return isDoInvoke;
	}

	public void setError(Throwable error) {
		this.error = error;
	}

	public Throwable getError() {
		return error;
	}

	public void setServerType(ServerType requestType) {
		this.serverType = requestType;
	}

	public ServerType getServerType() {
		return serverType;
	}

	public void setServerHandler(ServerHandler responseHandler) {
		this.serverHandler = responseHandler;
	}

	public ServerHandler getServerHandler() {
		return serverHandler;
	}

	public void setChannel(RsChannel channel) {
		this.channel = channel;
	}

	public RsChannel getChannel() {
		return channel;
	}

	public void setExecFilter(ExecFilterType execFilter) {
		this.execFilter = execFilter;
	}

	public ExecFilterType getExecFilter() {
		return execFilter;
	}

	public Protocol getProtocol() {
		return protocol;
	}

	public void setProtocol(Protocol protocol) {
		this.protocol = protocol;
	}

	public HttpRequest getHttpResuest() {
		return httpResuest;
	}

	public void setHttpResuest(HttpRequest httpResuest) {
		this.httpResuest = httpResuest;
	}
	
	
}